package game.module.nn.dao;

import java.io.File;
import java.nio.charset.Charset;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.Files;

import game.module.nn.bean.NnJindouCfg;
import game.module.sss.bean.SssJindouCfg;
import lion.common.Reloadable;

public class NnJindouTemplateCache implements Reloadable{
private static Logger logger = LoggerFactory.getLogger(NnJindouTemplateCache.class);
	
	static class SingletonHolder{
		static NnJindouTemplateCache instance = new NnJindouTemplateCache();
	}
	
	public static NnJindouTemplateCache getInstance() {
		return SingletonHolder.instance;
	}
	
	private volatile List<NnJindouCfg> templateList;

	@Override
	public void reload() {
		// TODO Auto-generated method stub
		try {
			String jsonStr = Files.asCharSource(new File("data/nnJindou.json"),Charset.forName("UTF-8")).read();
			ObjectMapper mapper = new ObjectMapper();
			templateList = mapper.readValue(jsonStr, new TypeReference<List<NnJindouCfg>>() {});
			logger.info("size={}", templateList.size());
		} catch (Exception e) {
			logger.error("",e);
		}
		
	}
	
	public boolean containsConfigIndex(int cfgIndex) {
		return cfgIndex < templateList.size();
	}
	public NnJindouCfg getTemplate(int cfgindex) {
		return (NnJindouCfg) (templateList.get(cfgindex));
	}
    public static void main(String[] args) {
    	NnJindouTemplateCache.getInstance().reload();
	}
}
